Repository navigation
cmake: function-visibility.txt entries for the /GL callers of #416, #433 and #438 - #491
Merged
gynt merged 1 commit intoNov 24, 2026
Merged
Conversation
…old#416, sourcehold#433 and sourcehold#438 sourcehold#416, sourcehold#433 and sourcehold#438 put six callers on cmake/compiler-flags-gl.txt after sourcehold#398 without an entry here: InGameMenu's MenuItemRenderFunction_InGameMenu_MainButtons and Roundtable's MenuItemActionHandler_Roundtable_Main (sourcehold#416), UpdateGhost (sourcehold#416), UpdateFireWatch and UpdateHunterDog (sourcehold#433), and UpdateCageDog (sourcehold#438). Each gets an entry at its address, its callees in address order. The /GL lines stay as they are. Each edge is measured as sourcehold#398's were: the caller's file compiled with the callee files in its unit, against the caller alone, quick_diff on main 7c2e4d6 with every function resolver that has a .cpp and every struct resolver on. The callees tried are the caller's /GL-listed callees below its address. A callee is listed when it raises the caller's ratio on its own, or when leaving it out of the full set lowers it; the listed set reads what the full set reads. - MainButtons: 0.8217 alone, 1.0000 with ButtonGmData::getPictureNumberInGm. - Roundtable_Main: 0.9391 alone, 0.9984 with GameSynchronyState::isAIPlayer. - UpdateFireWatch: 0.3834 alone, 0.9980 with checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, the same as with all four of its /GL callees; leaving one of the four out reads 0.7178 (checkIfCitizenUnitIsAliveBasedOnState) and 0.6606 (hasUnitReachedDestination). makeUnitStopWalkingByClearingPathProgressState and commitUnitLocation change nothing. - UpdateGhost: 0.5214 alone, 0.9712 with hasUnitReachedDestination. makeUnitStopWalkingByClearingPathProgressState changes nothing. - UpdateHunterDog: 0.3336 alone, 1.0000 with its four callees and with all five of its /GL callees; leaving one of the five out reads 0.9944 (makeUnitStopWalkingByClearingPathProgressState), 0.7283 (checkIfCitizenUnitIsAliveBasedOnState), 0.9298 (hasUnitReachedDestination), 0.9114 (hasTunnelerNotFinishedDigging). resumeMovementIfNoAttackTarget changes nothing. - UpdateCageDog: 0.2829 alone, 1.0000 with its four callees and with all seven of its /GL callees; leaving one of the seven out reads 0.8651 (makeUnitStopWalkingByClearingPathProgressState), 0.7162 (checkIfCitizenUnitIsAliveBasedOnState), 0.4142 (hasUnitReachedDestination), 0.9949 (tryAttackUnitID, which sourcehold#438 added to the /GL list for it). buildingIsAccessible, resumeMovementIfNoAttackTarget and commitUnitLocation change nothing. sourcehold#473 and sourcehold#475 put UpdateSiegeTent and UpdateHorseArcher_DoShooting on the /GL list; neither calls a /GL-listed function, so neither gets an entry. UpdateHorseArcher calls UpdateHorseArcher_DoShooting, which sits below it, but reads worse with its body (0.9929 with hasUnitReachedDestination, 0.9906 with both), so its entry stays as it is. With every .cpp of main as the build list, cmake/function-visibility-units.py now makes 24 units holding 116 source files (108 before): the six callers, tryAttackUnitID and makeUnitStopWalkingByClearingPathProgressState join the existing groups. No internal names clash, and the 13 names it skips are the ones it skipped before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 24, 2026
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 29, 2026
…h, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on (sourcehold#514) * header: UnitState, UnitInstructionType and EntityType values that UpdateEngineer uses Names for the values UpdateEngineer (0x00564250) uses and main's enums don't name yet, so its text needs no casts to the enums. They take main's <PREFIX>_UNKNOWN_<n> form, except 105 and 124, which take the names gynt gave them in his PR 293: US_RALLYING and US_DIG_MOAT. New enumerators only; no value or type changes. - UnitState 10, 13, 14, 15, 16, 105 and 124: the state switch at 0x00564331 (cmp eax, 0x7d; byte table 0x00565F88, jump table 0x00565F1C) gives each an arm of its own: 10 at 0x00565B54, 13 at 0x00565931, 14 at 0x00565A0A, 15 at 0x00565AA8, 16 at 0x00565C86, 105 at 0x00564654 and 124 at 0x00564A37. The function stores them into Unit::state (mov word ptr [reg + 0x138880C]): 10 at 0x005648F1 and 0x00565AEA, 13 at 0x00565925, 105 at 0x0056439E, 0x00564F62 and 0x0056527E, 124 at 0x005644AB (behind the dig-moat order, UIT_DIG_MOAT) and 0x00564A37; and into Unit::cachedState ([reg + 0x138880E]): 14 at 0x005659E5, 15 at 0x00565708, 105 at 0x0056547B. 105 is the walk to the rally point or the assembly tile. - UnitInstructionType 25 (UIT_UNKNOWN_25): Unit::targetingType ([reg + 0x13888E8]) is compared with 25 at 0x00565762 and set to 25 at 0x00565AE1. - EntityType 8 (ET_UNKNOWN_8): the projectile type UpdateEngineer passes to UnitsState::shootProjectile (push 8 at 0x00565C4C). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00551980 94.1% (100.0% with OPENSHC_FUNCTION_VISIBILITY_UNITS on) Units::UpdatePitchman, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 6401342 at 43.99%, 3cc1249 at 49.22%, then 974c32f's clang-format), through the forms on our development branches. The text reads a true 100.0 / 100.0 when updateBuildingSignpostCounter is not visible to it, which is how the original was built (see the end), and main's function-visibility manifest can say so: with OPENSHC_FUNCTION_VISIBILITY_UNITS on and this unit's entry (a commit of its own after the units), it reads 100.0 / 100.0 with no callee hidden by hand. With the option off, the default, the counter's /GL line shows it the body and it reads 94.1 / 81.7. The statements are his; what the text needed is how they are arranged. 1. Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy of the slot is gone. The original keeps the global itself in a register and loads it again only behind a call that may change it, which a local copy never does. 2. The twelve state blocks are one if / else-if chain whose arms fall out of it, instead of separate `if (state == X) { ...; return; }` blocks (with returning blocks the compiler keeps the earlier of two identical tails, with arms that fall out of a chain the later one, as the original has). 3. The working path as the fall-through, in two places: behind setDestinationForUnit (je at 0x00551B88 to the US_DISAPPEAR exit) and behind setWorkplaceBuildingEntryAsTarget (je at 0x00551F4A to the ULS_REMOVE exit), each `if (call) { rest } else { exit }` where the draft had an early exit. 4. Three more branches the original's way round: one early exit turned into the last exit of its block, and two if / else with their arms exchanged (each negates one condition and exchanges the two blocks). 5. The fade countdown without `(char)` casts (a char in main's header); the calls that return BOOLEnum tested by truthiness; the pitchman's own states by their names in UnitState_PitchMan (through `state.pitchMan`, as UpdateWheatFarmer does), the shared states and the resting state 5, which has no entry there, by the generic names; the destination numbers by their enum names. Visibility. The original reads the slot and loads `this` again behind the working state's first updateBuildingSignpostCounter call (0x00551C22; slot at 0x00551C2F, `mov ecx` at 0x00551C45); with that callee visible our compiler does neither. Behind commitUnitLocation (0x00552035) the original keeps the unit pointer in esi; ours does too now that commitUnitLocation's callee setupUnitSharingCurrentTilePosition and its callee setupUnitSharingTileIDs are visible (both on the /GL list since PR 378). UpdateBadBuildingGallows and UpdateBadBuildingDungeon need the counter's body (main's manifest says so), and this unit must not see it; one /GL list cannot say both, the manifest can: the counter stays in Gallows' and Dungeon's wrapper, and this unit's wrapper holds every callee it names. Measured with real builds of main e3646a8 with this branch: 294 sources (main's /GL list, the fade countdown's users, the two units of this branch with their callee closures and every file of a manifest group that touches them), 304 functions, every resolver of the list on, BUILD_OK each: - option off, the default build: 94.1 / 81.7; - option on, with this unit's entry (the manifest commit after the units): 100.0 / 100.0, no diff entry. On an earlier tree (main 8e1e77f with PR 378's earlier head) the option alone, with no entry for this unit, read 53.0 / 43.9: its callees in the units wrapper are opaque to it. The status line carries the default build's number. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00564250 81.8% (100.0% with OPENSHC_FUNCTION_VISIBILITY_UNITS on) Units::UpdateEngineer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 01f37c5 at 31.91%, e3244b8 at 36.74%, 20c9a72 at 36.79%, then 974c32f's clang-format), through the forms on our development branches. The text reads a true 100.0 / 100.0 when two callees are not visible to it, which is how the original was built (see the end); in the default build, where this tree's /GL list shows it both, it reads 81.8 / 75.8. The statements are his; what the text needed is how they are arranged. One store of the draft is gone (item 9). 1. State 0, the rally point first: `if (goToRallyPoint != 0) { ...; return; }` in front of the moat tests (0x00564383), with one `someCount27++; return;` behind `if (findFreeEngineerAssemblyTile(...)) { set the destination }`. 2. State 0, moats: `moat > -1` (cmp -1 / jle at 0x005644FB). FILL_MOAT's two failures are two arms, `if (setXYBasedOnMoatID(moat, 2, ...) == 0) { fail } else { if (setDestinationForUnit(...)) { ...; return; } fail }`, and the first arm is written `targetingType = 3; someCountDown -= 20;`: the original computes the unit pointer in front of the countdown and stores through it behind (0x00564576 .. 0x00564592), which also keeps the moat in edi (0x005644F9). The second arm joins DIG_MOAT's failure through eax (0x005645E8 to 0x005644C0), the compiler's own merge. 3. State 0's last choice as a chain with two equal arms: `resourceToDeposit != 0` -> sit down, `distance > 400` -> idle, `distance > 96` -> state 2, else -> state 2. The original loads the distance into a register and branches (movzx at 0x0056460A, cmp ax at 0x00564611, one `state = 2` at 0x00564620), as the soldiers' chains do; a two-way if / else compiles to setle. With the branch back, the function's constant 1 sits in edx as in the original. 4. State 105: one `someCount27++; return;` behind `if (reached) { if (find...) { set the destination } else { facingDirection = 4; } }`. The compiler copies that tail itself (0x005646D8 and 0x005646F9); written twice, it merged one copy with the rally block's. 5. The walk states: movementSpeed as `resourceToDeposit != 0 ? 2 : 1` (setne and a 32-bit add at 0x005647A9 / 0x005647AC, and at 0x0056495E). 6. The two dig states: the dig tile's x and y as int locals in front of xyAreValid, used for the check and for the tile (movsx edi / ebp at 0x00564A87 / 0x00564A8E, kept across the call; the orientation call reads the fields again); in the dig state, the unit on the tile as an int local in front of its test (movsx at 0x00564B71). 7. State 2 and the idle state: the idle flag set and tested in two statements (0x00564E74 / 0x00564E80); `state = 105; someCount27++;` in that order (the unit pointer is computed in front of the add and the store stands behind it, 0x00564F4C .. 0x00564F62 and 0x0056526C .. 0x0056527E); in the idle state, the manned engine's index as an int local behind the targeting test (movsx at 0x00565202, 32-bit compare at 0x00565209); in state 2 the draft's early return, `if (!isAIPlayer(units[slot].owner)) { return; }`. In the idle state the rest stands inside `if (DAT_UnitHasBecomeIdle != 0) { ... }`: a unit that is not idle goes to the state's last test instead of returning (je at 0x00565133 to 0x00565287). That test cannot hold there, the two moat targeting types set the flag just above, so what happens is the same. 8. Walking to a siege building: the engineer count compared signed, `employeeCount < (int)getRequired...()` (jge at 0x0056535A), and both entry distances as `<= 1` (cmp 1 / jg at 0x0056537D and 0x0056539B). 9. The oil pot (state 9): the carrying arm first (0x005654B2); no local for the worker slot, the call passes `currentEmployeeCount` and the compiler keeps the incremented value in ebx across hasUnitReachedDestination by itself (0x005654F0); `workerUID[0] = uid;` in front of `field_0x3c4 = 1;` (0x0056567F .. 0x0056568C) and `workerID[0] = slot;` in front of the frame statement (0x005656A7 / 0x005656AE); `animationCycleNumber = 0;` at the start of both arms of the uid test (the original stores it between the compare and the jump, 0x005656D0); the pitch test as the original's chain, `pitch <= 0` -> fetch, `engineerUnitID != 0` -> roam, `pitch < 9` -> fetch (0x005656D8, 0x005656E2, 0x00565729). Fetching pitch (state 12): the storage building in an int local. **The draft also stored it into animationFrame and read it back from there; the original keeps it in edi and stores it only to horseOriginStablesBuildingIndexUnk (0x0056580D, 0x00565821).** The failed access test is the else arm, out of line as in the original (je at 0x0056582F to 0x005658DB). 10. The fade state's end as `if (isDisappearingUnk != 0) { ...; return; } else { commitUnitLocation(...); return; }`: the commit arm stands out of line. 11. The fade countdown without `(char)` casts (a char in main's header); the moat flag as OpenSHC::Map::LogicHelpers::L_MOAT; aiUnitBehaviourType against AIUBT_ENGINEERING / AIUBT_HARASS_SIEGE; the orientation against CD_UNSPECIFIED; state 104 by UnitState's US_CLIMBING_LADDER; the states 10, 13 .. 16, 105 and 124, the instruction type 25 and the projectile type 8 by the names the header commit before this one adds; the siege-state check type set to -2, as main's UpdateMerchant writes it. 12. What stays as it looks: states 14 and 15 keep a body each, because the original has two arms (0x00565A0A, 0x00565AA8) and one shared arm loses the match; `moat > -1` stays, as the original compares with -1; and the two isAIPlayer calls, clearOrDeselectUnitFromSelection and the pitch storage lookup read the unit's owner again instead of the `owner` local, which loses the match there. Headers this file runs into (not changed here): findNearestFriendlyMoatTileForDigging is declared BOOLEnum but returns a moat index, -1 for none; advanceMoatDigProgress and removeMoat are declared BOOLEnum and the original compares them with 1; getRequiredEngineerCountForSiegeBuilding returns undefined4, hence the `(int)`. Visibility. The original keeps the unit pointer across xyAreValid (0x00564AB8) and across isAIPlayer (0x00564ECC, 0x005651DA), so xyAreValid gets a /GL line here (isAIPlayer has one already). Two callees it does not see through: - updateBuildingSignpostCounter: it loads `this` again in front of the second call (0x00565A31) and reads the slot again behind it (0x00565A3B); with that callee visible our compiler does neither and gives the target building and the slot each other's registers for the whole function; - getStorageBuildingForResourceTypeAndAmount: it reads the slot again behind the call (0x0056580F). Ours does that only while the lookup's own helper getBuildingStorageTypeForResourceType is not visible (or the lookup itself is not); with both on the /GL list the compiler knows the lookup writes nothing and keeps the pointer. With OPENSHC_FUNCTION_VISIBILITY_UNITS on, main's manifest says it: this unit's entry (the manifest commit after the units) names the callees it needs and neither of those two, which stay in the wrappers of their own callers. Measured with real builds of main e3646a8 with this branch: 294 sources (main's /GL list, the fade countdown's users, the two units of this branch with their callee closures and every file of a manifest group that touches them), 304 functions, every resolver of the list on, BUILD_OK each: - option off, the default build: 81.8 / 75.8; xyAreValid and isAIPlayer 100.0; - option on, with this unit's entry (the manifest commit after the units): 100.0 / 100.0, no diff entry; xyAreValid 100.0. getBuildingResourceAmountByUid is main's plain function here, with no header body. On an earlier tree, with the two callees' /GL lines taken off a local list, it read 100.0 / 100.0 too. The status line carries the default build's number. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * cmake: function-visibility.txt entries for UpdatePitchman and UpdateEngineer The two units sit on cmake/compiler-flags-gl.txt (the commits before) and get an entry each, at their addresses, their callees in address order. No entry names BuildingsState::updateBuildingSignpostCounter: the original treats it as opaque in these units (it reads the slot and loads `this` again behind it), while UpdateBadBuildingGallows and UpdateBadBuildingDungeon need its body (their entries say so). With OPENSHC_FUNCTION_VISIBILITY_UNITS on, the counter stays in their wrapper and the units' wrapper holds the callees listed here, which is what a single /GL list cannot say. Each edge is measured as sourcehold#491's were: the unit's file compiled with the callee files in its unit, against the unit alone, quick_diff on an earlier stack (main 8e1e77f merged in) with every function resolver that has a .cpp and every struct resolver on. The callees tried are the unit's whole callee closure without the counter. A callee is listed when leaving it out of that set lowers the ratio; the listed set reads what the whole set reads. UpdateEngineer's edges were measured with getBuildingResourceAmountByUid marked `inline`; it reads the same with the getter plain, as it is on main and here, and the real builds below are of the plain getter. - UpdatePitchman: 0.5695 alone, 1.0000 with its 10 listed callees (the whole set of 22 reads 1.0000). Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.6217, IncrementAndOptionalUpdateAVValueRelated 0.7404, hasUnitReachedDestination 0.7954, SetStateToFreetimeWalking 0.8317, ConsiderHavingABreakNowUnk and UpdateWorker_ConsiderTakingABreakUnk 0.9604 each, ComputeGoodsProduced 0.9652, and each of sourcehold#378's setupUnitSharingTileIDs, setupUnitSharingCurrentTilePosition and commitUnitLocation 0.9961. - UpdateEngineer: 0.4314 alone, 1.0000 with its 8 (the whole set of 21, its /GL callees without the counter and without the storage lookup and its helper, reads 1.0000). Left out, hasUnitReachedDestination reads 0.5912, isAIPlayer 0.9442, sitDownIfStanding 0.9596, xyAreValid 0.9740, deselectUnit 0.9758, getBuildingResourceAmountByUid 0.9941, makeUnitStopWalkingByClearingPathProgressState 0.9953, changeDestinationByAmount 0.9976. Neither needs the storage lookup (getStorageBuildingForResourceTypeAndAmount) or its helper, and UpdateEngineer must not see them (it reads the slot again behind the lookup, 0x0056580F), so they stay in the wrapper of their own callers. Real builds, main e3646a8 with this branch, BUILD_OK each: - narrow, 294 sources (main's /GL list, the fade countdown's users, the two units with their callee closures and every file of a manifest group that touches them), 304 functions, every resolver of the list on: option off, UpdatePitchman 94.1 / 81.7 and UpdateEngineer 81.8 / 75.8; option on, both 100.0 / 100.0 with no diff entry. UpdateBadBuildingGallows, UpdateBadBuildingDungeon, UpdateIronMine, UpdateInnkeeper, the counter, the getter and xyAreValid read 100.0 in both. - full, on this branch before the header commit and the review fixes (the enum names, -2 for 254, comments, `int const`, this entry moved to its address), which leave both units' quick_diff listings and every generated wrapper unchanged; 2,913 sources (every file of main but the 12 that don't compile there, resolvers off for those), every function and data resolver on, 2,931 functions, 0 failed: option off against main 655adce's build (2,925 functions; main e3646a8 adds only PR 510's four files): average 99.53 against 99.54; UpdatePitchman 94.1 / 81.7, UpdateEngineer 81.8 / 75.8; nothing on main reads lower; UI::Menu::Constructor_Menu 98.4 -> 100.0 and handleMenuItems 97.9 -> 100.0 (they follow where functions land in the image); PR 510's four as on main; option on against main e3646a8's build (2,929 functions): average 99.46 against 99.46; both units 100.0 / 100.0; nothing on main reads lower; UpdateMinerIronFetcher 98.0 -> 100.0, as in the earlier tree's build. On an earlier tree (main 8e1e77f with PR 378's earlier head), the option on with no entry for the unit read UpdatePitchman 53.0 / 43.9. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Gynt <gynt@users.noreply.github.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 30, 2026
…d#515, sourcehold#516 and sourcehold#518 (sourcehold#534) sourcehold#515, sourcehold#516 and sourcehold#518 put twelve units on cmake/compiler-flags-gl.txt. UpdateCamel, UpdateLady and UpdateFireEater have an entry here already and read 100.0% with OPENSHC_FUNCTION_VISIBILITY_UNITS on; the other nine have none. In that mode the members of every group leave the /GL list, among them the helpers in the group that holds hasUnitReachedDestination, so a /GL unit without an entry no longer sees them: the nine read 37.7% to 65.7% in main ff7e56e's full build in that mode, the build the real builds below compare against. Each gets an entry at its address, its callees in address order. The /GL lines stay as they are. Each entry names only callees that are already members of the group that holds hasUnitReachedDestination, so the nine join that group and nothing else moves: no other function leaves the /GL list, and no other function sees a body it did not see before. The nine's other /GL callees (setDestinationForUnit, moveToFreeTileNearby, acquireShootTarget, shootProjectile and the rest of their closures) stay opaque to them, and they read 100.0% / 100.0% that way (raw / normalised: reccmp_report.py's normalised figure ignores call and tail-jump targets and resolver addresses). Naming each unit's whole /GL callee closure instead would put 28 more functions in that group: with every .cpp of main as the build list, cmake/function-visibility-units.py then makes 22 wrapper units holding 178 source files, against 25 holding 141 on main (the nine units and 28 of their callees join, and three smaller groups merge in). Those 28 would leave the /GL list for main's callers that have no entry (processUnitMove, exitLadder, unitClimbing, UpdateHorseArcher_DoShooting and others). Each caller-callee pair is measured as sourcehold#491's were: the unit's file compiled with the callee files pasted in front of it, against the unit alone, quick_diff on main ff7e56e. The data resolvers were switched on with tools/reimplementation-control/enable_reimplemented_data.py and the function resolver of every .cpp in the build list with tools/reimplementation-helper/batch/enable_local_functions.py (locally, not committed). The callees tried are the group's members that the unit calls directly or through another member it calls (so indirect ones too: commitUnitLocation's two callees for UpdateTunneler, ConsiderHavingABreakNowUnk behind UpdateWorker_ConsiderTakingABreakUnk for UpdateWheatFarmer), not callees reached only through functions outside the group. A callee is listed when leaving it out of that set lowers the ratio; the listed set reads what the whole set reads. quick_diff is stricter than reccmp about register names; the real builds read each unit at 100.0%. - UpdateMother: 0.5668 alone, 0.9918 with its 3. Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.7900, hasUnitReachedDestination 0.8918, changeDestinationByAmount 0.8994. - UpdateChild: 0.5564 alone, 0.9993 with its 4. Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.8294, hasUnitReachedDestination 0.9153, hasTunnelerNotFinishedDigging 0.9881, changeDestinationByAmount 0.9976. - UpdateTunneler: 0.6433 alone, 0.9897 with its 2. Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.7619, hasUnitReachedDestination 0.6726. commitUnitLocation and its callees setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs change nothing. - UpdateWheatFarmer: 0.4115 alone, 0.9988 with its 8. Left out, IncrementAndOptionalUpdateAVValueRelated reads 0.7775, ConsiderHavingABreakNowUnk 0.9838, SetStateToFreetimeWalking 0.9898, ComputeGoodsProduced 0.9784, checkIfCitizenUnitIsAliveBasedOnState 0.8193, hasUnitReachedDestination 0.9462, changeDestinationByAmount 0.9130, UpdateWorker_ConsiderTakingABreakUnk 0.9838. - UpdateCrusaderArcher: 0.6723 alone, 0.9869 with its 3. Left out, xyAreValid reads 0.9709, hasUnitReachedDestination 0.7176, changeDestinationByAmount 0.9853. - UpdateCrossbowman: 0.6537 alone, 0.9964 with hasUnitReachedDestination. - UpdateLadderman: 0.4106 alone, 0.9938 with hasUnitReachedDestination. - UpdateArabianArcher: 0.5843 alone, 0.9944 with hasUnitReachedDestination. - UpdateFireThrower: 0.6844 alone, 0.9965 with hasUnitReachedDestination. makeUnitStopWalkingByClearingPathProgressState, which UpdateMother, UpdateChild and UpdateWheatFarmer call, changes nothing for any of them. With every .cpp of main as the build list, cmake/function-visibility-units.py now makes 25 wrapper units holding 150 source files (141 before): the nine join the group that holds hasUnitReachedDestination, and no other file changes group. CMake reads this file only with the option on, so the default build is unchanged. Real builds of this change on main ff7e56e, BUILD_OK and 0 failures each: - full, option on: every .cpp of main with all function and data resolvers on (the 12 files that don't compile since sourcehold#509's sync left out), 3,025 files and 3,043 functions, against main ff7e56e built the same way. The nine read 100.0% / 100.0% (main: 37.7% to 65.7%); nothing else reads differently. - small, both modes: main's /GL list, every .cpp that reads Unit::disappearFadeAlphaCountdown, the twelve units and UpdatePriest with their callee closures, and every file of a group that touches them, 485 files and 495 functions. All twelve read 100.0% / 100.0% in both modes; UpdatePriest, which has no entry, 100.0% off and 72.0% / 68.9% on, as on main. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Dec 1, 2026
…er and UpdateSlave from gynt's units branch (100%, three with OPENSHC_FUNCTION_VISIBILITY_UNITS on) (sourcehold#537) * reimplement: SHC_3BB0A8C1_0x0053C300 100.0% Reimplemented Units::UpdateShield at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: f791380 at 49.29%, cf15f54 at 52.39%, 6565c1b, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our development branches, where its history is (94.0% there, on main 1f87a13). What the match needed, against the draft: - The state it starts in is picked by an if / return pair, as in main's UpdateBatteringRam (sub / neg / sbb / and at 0x0053C382); the draft had a ternary. - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone. - The scan for engineers tests its six conditions as six `if (...) { continue; }` statements, the counts are cleared with memset, the distances compare with the engineer first, and the tests read `> 16` and `< 1`, as the original compares. The tick test reads `^ 8` where the draft had `^ 0xfffffff8`, the same value under `& 15`. - The AI check's loop and the two blocks that send the engineer to work are loops of one over manningEngineerRef and engineerIDs[9][1]: the first is a loop in the original too (0x0053C4C3), the others make it compute the unit's offset anew (0x0053C4D9, 0x0053C744), the start of a loop the compiler unrolled. Written out with index 0 (the first as a do / while (0), as its tests break out of it), they read 0.7650, 0.9848 and 0.9913 in quick_diff, against 0.9978. - The search for the capturing owner is a for loop from 1 to 8 with a found flag, the source form that matches (the binary has no flag: the loop at 0x0053C6A7 returns at its end, 0x0053C6B4), and, the last step, it has a local of its own that is copied behind the capture, as in main's UpdateBatteringRam, where the parked text searched in the local that holds the shield's owner. With it the scan's bound stays in ebx (loaded at 0x0053C57F, compared at 0x0053C682): 0.9859 -> 0.9978 in quick_diff with the /GL callees in the unit (the one line left, 0xffff against -0x1, is the same instruction). The bound read as the global itself instead of through a local came first (0.9827 -> 0.9859). - createTribe gets the owner of units[searched], where searched is the counter the scan left behind (0x0053C70F); the draft passed the shield's own owner. The same call is in main's UpdateBatteringRam, and so is the next one: addUnitToTribe gets the tribe as unitID and the shield as tribeID (0x0053C736), with a fixme for each. compiler-flags-gl.txt gets UpdateShield.cpp only: the two callees it has to see are on main's list already (quick_diff 0.5457 without hasUnitReachedDestination, 0.8707 without deselectUnit, 0.5152 without both). On main, this round's text pass: main's name for state 108, BOOLEnum calls by truthiness, `++`, `const` on locals, the fade countdown without its cast, UpdateBatteringRam's names and comments for the scan and its if / return pair for the first state. The quick_diff listing is the same before and after it. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them), once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files, 3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text edits; quick_diff gives the same listing of every file before and after them. It reads 100.0 / 100.0 in all of them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0054F860 96.3% 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on Units::UpdateHunter, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 76bb533 at 48.51%, 9f9546f at 52.15%, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our development branches, where its history is (95.3% there). 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its entry in this branch's last commit; 96.3% in the default build, so the status line carries that number, as UpdatePitchman's does. What the match needed, against the draft: - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone. - The states are one if / else-if chain whose arms fall out of it, where the draft had a block per state that returns; the shooting state keeps its closing return. - The shooting state has the "look for another deer, or go home" block once in the arrow part, behind a flag the arrow sets, and once behind it (0x0054FF45, 0x0054FF71). The draft had it twice in the arrow part. The flag, arrowFired, is the source form that matches: the binary has none, four tests jump to 0x0054FF45. - The early exits go the original's way round: the other hunter's uid test, "the deer is gone" and "the deer is within 20" first when chasing, the walk to the post with the failed setDestinationForUnit as the else arm. - The substate set when the hunter gets back to his post is (mapTimeInTicks & 1) + 2 with no cast (0x00550529), and the two height sums of the shot have the terrain height first. What the option is for: the original knows ten of its callees and treats two, updateBuildingSignpostCounter and getResourceCountThatCanBeDeposited, as opaque (it reads the slot again behind them). Both are on main's /GL list, so the default build sees their bodies: quick_diff reads 0.9857 with all /GL callees in the unit, 0.9991 with the ten only, where the one line left, 0xff against -0x1, is the same instruction. With the option on the two are in other wrapper units. compiler-flags-gl.txt gets UpdateHunter.cpp, as it has UpdatePitchman.cpp. On main, this round's text pass: main's names (UnitState_Hunter) for the hunter's states 0 to 11 and 106, through state.hunter (as main's UpdatePitchman and UpdateWheatFarmer do for theirs), and for the resting state (USH_RESTING_7); 108 to 111, 113 and 121 keep the shared US_ names; DNE_UNKNOWN_2 and RT_MEAT; BOOLEnum calls by truthiness, `++` / `--`, `const` on locals, the fade step stored as -2, no `(char)` on the frame tables and the fade countdown, unused `using` lines dropped, and the local for the slot in front of commitUnitLocation dropped. The quick_diff listing is the same before and after it. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them), once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files, 3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 / 100.0, with it off 96.3 / 86.9. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00553AE0 94.6% 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on Units::UpdateAppleFarmer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 69e0814 at 43.32%, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our development branches, where its history is (94.1% there). 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its entry as this branch's last commit leaves it; 94.6% in the default build, so the status line carries that number, as UpdatePitchman's does. What the match needed, against the draft: - The branches of four states the original's way round, read off it one basic block at a time: going to the workplace and waiting for a tree (the call that works first), the granary walk (its failure path written out), the deposit (one local for getResourceCountThatCanBeDeposited's result). - The last steps: every access reads the unit through DAT_CurrentUnitSlotID::instance (our parked text still indexed some through the draft's `unitID` and one state through a local for the slot, across a setDestinationForUnit call, which is not a named callee and stays opaque), and the waiting state stores the slot into the orchard's workers[] before it reads the frame, as main's UpdateDairyFarmer does. In quick_diff with the group's callees in the unit 0.9899 -> 0.9984 (the one line left, 0xff against -0x1, is the same instruction). Only together: 0.9844 without the second step, 0.9891 with the state's local kept. What the option is for: the original reads the slot again behind getResourceCountThatCanBeDeposited, which is on main's /GL list, so the default build sees its body and keeps the register (quick_diff 0.9820 with it, 0.9984 without). compiler-flags-gl.txt gets UpdateAppleFarmer.cpp, as it has UpdatePitchman.cpp. On main, this round's text pass: main's names for states 108 and 121 and for DNE_UNKNOWN_2, BOOLEnum calls by truthiness, `++` / `--`, `const` on locals, no `(char)` on the frame tables and the fade countdown, the unused `using` lines and one unused include dropped, USAF_WAITING_1 for the resting state and the farmer's own state type for the local. The quick_diff listing is the same before and after it. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them), once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files, 3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 / 100.0, with it off 94.6 / 89.6. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0056E190 100.0% Reimplemented Units::UpdateJester at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 146023d at 42.00%, 93b5ce0 at 50.14%, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our development branches, where its history is (94.1% there). What the match needed, against the draft: - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone. - The states are one if / else-if chain whose arms fall out of it, where the draft had a block per state that returns, and the first death state tests "the animation is over" first. - gfxBase is declared at the function's top (with a comment): the original zeroes a register for it in the first block and keeps the owner in the frame (0x0056E1C7). - The random roll is read once into an int local and compared twice (0x0056E336). The text stores the wandering state in two arms; the original has the store once (0x0056E3AF) and so has ours, the compiler merges the two arms (one arm for both cases loses the match: quick_diff 0.9950 and 0.9894 against 0.9986). - The last steps, on this main: two locals our parked text had for the slot are gone, one around changeDestinationByAmount in the walk-up state and one in front of commitUnitLocation in the fade state. With the callees' bodies visible they cost (quick_diff with the /GL callees in the unit 0.9612 -> 0.9936 -> 0.9958). And the walk-up state tests `movementSpeed < 1`, a compare with the constant 1 the original holds in bp, where the draft had `<= 0`, the same values (0.9958 -> 0.9986; the one line left, 0xff against -0x1, is the same instruction). compiler-flags-gl.txt gets UpdateJester.cpp only: the eight callees it has to see are on main's list already (quick_diff without each: checkIfCitizenUnitIsAliveBasedOnState 0.8217, changeDestinationByAmount 0.8870, hasUnitReachedDestination 0.9627, makeUnitStopWalkingByClearingPathProgressState 0.9859, hasTunnelerNotFinishedDigging 0.9944, commitUnitLocation, setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs 0.9958 each; 0.5465 without any). On main, this round's text pass: main's names for states 2, 3 and 108, BOOLEnum calls by truthiness, `++` / `--`, `const` on locals, decimal constants, the fade step stored as -2, no `(char)` on the frame tables and the fade countdown and no `(byte)` on the random number, unused `using` lines and one unused include dropped. The quick_diff listing is the same before and after it. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them), once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files, 3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text edits; quick_diff gives the same listing of every file before and after them. It reads 100.0 / 100.0 in all of them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00571C00 91.7% 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on Units::UpdateSlave, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 1f2f3bf at 43.44%, cfa098f at 49.88%, 6565c1b, 8ca7861 (the file again, whole) and the style commit 974c32f), through the forms on our development branches, where its history is (87.4% there). 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on, with its entry as this branch's last commit leaves it; 91.7% in the default build, so the status line carries that number, as UpdatePitchman's does. What the match needed, against the draft: - Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone. - The fill-moat branch counts the moat's countdown down first, then sets the targeting type, on every path (in the source, the path where setXYBasedOnMoatID returns 0 has the two the other way round, as main's UpdateEngineer does; the other order loses the match, quick_diff 0.9710 against 0.9792). The moving state tests "delay running" first; its moat branch and the digging walk go the original's way round. - The last steps, on this main (quick_diff with the group's callees in the unit, each on the one before): - the parked text's local for the slot across changeDestinationByAmount is gone, the dig state's two frame arms are the other way round, and the unit on the dig tile is read once into a local, as in main's UpdatePikeman (0.9555 -> 0.9654); - state 0 ends in a chain of three arms whose last two store the same state, as in main's UpdateEngineer: the original branches on 400 only (0x00571EFD), a two-way if / else and an early return for the 400 arm become a setcc instead (0.9683), and 0.9654 -> 0.9764 for the chain on the earlier text. The 96 of the middle arm is UpdateEngineer's number, by analogy; the original has no 96 here. - the moat's owner is read through a local for returnOwnedMoatAtTile's result (0.9764 -> 0.9792). What is left of the 0.9792 is how quick_diff spells constants, two-global sums and the timeGetTime import. - `(int)` on the tick sum in front of `% 40`: the original divides signed (cdq, idiv), as in main's UpdatePikeman; the draft's remainder is unsigned, which differs once the sum passes 2^31. What the option is for: getBuildingFlammabilityFactor is on main's /GL list, so the default build sees its body, and the original treats it as opaque (quick_diff 0.9284 with it, 0.9792 without). compiler-flags-gl.txt gets UpdateSlave.cpp, as it has UpdatePitchman.cpp. On main, this round's text pass: main's names for states 2, 104, 105, 108 and 124 and for CD_UNSPECIFIED and L_MOAT, BOOLEnum calls by truthiness, `++` / `--`, `const` on locals, no `(char)` on the frame tables and the fade countdown and no `(short)` where main's UpdatePikeman has none, the string's text above its pointer, one unused include dropped, CD_SOUTH for the rally's facing, an else-if and one else less around the two returns. The quick_diff listing is the same before and after it. The compares with -1 (0.9693 with >= 0), the two closing stores of the dig state written on both paths (0.9622 when written once), and the US_APPEAR stores of the sheet offset and the speed in both arms (0.9759 to 0.9782 hoisted) are measured, with comments in the text. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised), on main 830fbd5: the small build of this branch's head (503 files, 513 functions: every /GL file of main, every .cpp that reads Unit::disappearFadeAlphaCountdown, the five units, the fourteen of sourcehold#515, sourcehold#516, sourcehold#518 and sourcehold#533 and UpdatePriest with their callee closures (UpdateSlave's without playVictory2BikFromPlayerToPlayer's, which doesn't link in a small build), two callers of standUpIfSeated and every file of a function-visibility group that touches them), once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK both. The full builds (3,041 files, 3,059 functions: every .cpp but main's three that don't compile, once off and once on) were made before the last text edits; quick_diff gives the same listing of every file before and after them. With the option on it reads 100.0 / 100.0, with it off 91.7 / 66.3. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * cmake: function-visibility.txt entries for UpdateShield, UpdateHunter, UpdateAppleFarmer, UpdateJester and UpdateSlave New entries for UpdateShield, UpdateHunter and UpdateJester; UpdateAppleFarmer's and UpdateSlave's, which main had before the files existed, each name two more callees. All name only callees that are already members of the group that holds hasUnitReachedDestination, so the five units join that group's wrapper unit and nothing else moves: no other function sees a body it didn't see before or loses one. Each caller-callee pair is measured as sourcehold#491's were (quick_diff, the unit's file with the callee files pasted in front of it, against the unit alone). The callees tried are the group's members that the unit calls directly or through another member it calls; one is named when leaving it out lowers the ratio, and the named set reads what the whole set reads: - UpdateShield 0.5152 alone, 0.9978 with its two: without hasUnitReachedDestination 0.5457, deselectUnit 0.8707. - UpdateHunter 0.4887 alone, 0.9991 with its ten: without IncrementAndOptionalUpdateAVValueRelated 0.6953, checkIfCitizenUnitIsAliveBasedOnState 0.9004, hasUnitReachedDestination 0.9201, ComputeGoodsProduced 0.9840, SetStateToFreetimeWalking 0.9880, UpdateWorker_ConsiderTakingABreakUnk and ConsiderHavingABreakNowUnk 0.9907 each, commitUnitLocation, setupUnitSharingCurrentTilePosition and setupUnitSharingTileIDs 0.9929 each. Not named: makeUnitStopWalkingByClearingPathProgressState (no change). - UpdateAppleFarmer 0.5793 alone, 0.9984 with its seven: without checkIfCitizenUnitIsAliveBasedOnState 0.8558, IncrementAndOptionalUpdateAVValueRelated 0.8580, ComputeGoodsProduced 0.8918, hasUnitReachedDestination 0.9408, SetStateToFreetimeWalking 0.9891; new in the entry, UpdateWorker_ConsiderTakingABreakUnk and ConsiderHavingABreakNowUnk, 0.9713 each. Not named: makeUnitStopWalkingByClearingPathProgressState (no change). - UpdateJester 0.5465 alone, 0.9986 with its eight: the numbers are in its commit. - UpdateSlave 0.5410 alone, 0.9792 with its three: without hasUnitReachedDestination 0.5245; new in the entry, xyAreValid 0.9173 and changeDestinationByAmount 0.9764. On top of the named callees, each /GL callee outside the group that the unit calls was tried one at a time, without its own callees: only updateBuildingSignpostCounter (UpdateHunter 0.9933), getResourceCountThatCanBeDeposited (UpdateHunter 0.9915, UpdateAppleFarmer 0.9820) and getBuildingFlammabilityFactor (UpdateSlave 0.9284) change a ratio, and all lower it. Full build of every file with the option on (3,041 files, 3,059 functions, BUILD_OK, 0 failures), against main 830fbd5's tree built the same way (3,036 files, 3,054 functions): nothing on main reads differently, and the five units read 100.0 / 100.0. It was made before the last text edits of the five units; quick_diff gives the same listing of every file before and after them. The generator makes 25 wrapper units holding 160 source files (155 on main): the five units join the group that holds hasUnitReachedDestination, and no other file changes group. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
gynt
pushed a commit
to gynt/OpenSHC
that referenced
this pull request
Dec 2, 2026
…t and UpdateMiller (sourcehold#535) sourcehold#534 gave the nine /GL units of sourcehold#515, sourcehold#516 and sourcehold#518 that had no entry in cmake/function-visibility.txt one, and left three for a follow-up: UpdatePeasant and UpdateMiller (sourcehold#533), and UpdatePriest, main's own unit. This adds the three, each at its address, its callees in address order. All three are on cmake/compiler-flags-gl.txt already (UpdatePriest was there before those PRs); that file stays as it is. With OPENSHC_FUNCTION_VISIBILITY_UNITS on, the members of every group leave the /GL list, among them the helpers in the group that holds hasUnitReachedDestination, so a /GL unit without an entry no longer sees them: in main e62246a's full build in that mode, the build the real builds below compare against, UpdatePriest reads 72.0% / 68.9%, UpdatePeasant 49.3% / 48.7% and UpdateMiller 51.7% / 46.2% (raw / normalised: reccmp_report.py's normalised figure ignores call and tail-jump targets and resolver addresses). UpdatePriest's entry names only callees that are already members of the group that holds hasUnitReachedDestination, as sourcehold#534's do. UpdatePeasant's and UpdateMiller's name members of that group and, each, one more /GL callee that is not in it: getDestination2EqualsGivenCoordinates for UpdatePeasant and standUpIfSeated for UpdateMiller. With the members alone they read 96.0% / 87.1% and 96.5% / 93.0% in an earlier full build of this branch with the option on (below). With that callee they read 100.0%, so it joins the group, and with the option on, CMake takes five more files off the /GL list: the three units, getDestination2EqualsGivenCoordinates and standUpIfSeated. Nothing else moves: getDestination2EqualsGivenCoordinates is called by UpdatePeasant only, and standUpIfSeated by UpdateMiller, standUpAllTribeUnits and updatePeasantSeatingAtBuilding (neither of the last two is on the /GL list or has an entry, so neither saw its body before or sees it now). No other function sees a body it did not see before. The three units' other /GL callees (setDestinationForUnit, resetUnitMovementState, clearHiddenFlagAndUpdatePosition, setWorkplaceBuildingEntryAsTarget, selectNewBlessingTarget, setUnitFacingDirectionTowardsTarget and the rest of their closures) stay opaque to them. Each caller-callee pair is measured as sourcehold#491's and sourcehold#534's were: the unit's file compiled with the callee files pasted in front of it, against the unit alone, quick_diff on main e62246a, with the data resolvers switched on by tools/reimplementation-control/enable_reimplemented_data.py and the function resolver of every .cpp in the build list by tools/reimplementation-helper/batch/enable_local_functions.py (locally, not committed). The callees tried are the group's members that the unit calls directly or through another member it calls (commitUnitLocation's callee setupUnitSharingCurrentTilePosition and, behind it, setupUnitSharingTileIDs, included), not callees reached only through functions outside the group; and, for UpdatePeasant and UpdateMiller, each /GL callee outside the group that they call, one at a time on top of the named members, pasted without its own callees unless it says "with its callees". A callee is listed when leaving it out of the set lowers the ratio; the listed set reads what the whole set reads. quick_diff is stricter than reccmp about register names; the real builds read the units at 100.0%. - UpdatePriest: 0.7534 alone, 0.9986 with its 5. Left out, makeUnitStopWalkingByClearingPathProgressState reads 0.9891, IncrementAndOptionalUpdateAVValueRelated 0.8859, checkIfCitizenUnitIsAliveBasedOnState 0.9510, hasUnitReachedDestination 0.9680, changeDestinationByAmount 0.9850. commitUnitLocation, its callee setupUnitSharingCurrentTilePosition and, behind it, setupUnitSharingTileIDs change nothing. - UpdatePeasant: 0.5329 alone, 0.9941 with its 3. Left out, checkIfCitizenUnitIsAliveBasedOnState reads 0.5880, getDestination2EqualsGivenCoordinates 0.9725, hasUnitReachedDestination 0.9684. Outside the group, on top of the two members, clearHiddenFlagAndUpdatePosition (with its callees) and setDestinationForUnit change nothing. - UpdateMiller: 0.5531 alone, 0.9973 with its 13. Left out, getBuildingResourceAmountByUid reads 0.9722, setupUnitSharingTileIDs 0.9947, standUpIfSeated 0.9913, sitDownIfStanding 0.9953, IncrementAndOptionalUpdateAVValueRelated 0.8442, ConsiderHavingABreakNowUnk 0.9914, SetStateToFreetimeWalking 0.9707, ComputeGoodsProduced 0.9661, checkIfCitizenUnitIsAliveBasedOnState 0.8008, hasUnitReachedDestination 0.9593, setupUnitSharingCurrentTilePosition 0.9947, UpdateWorker_ConsiderTakingABreakUnk 0.9914, commitUnitLocation 0.9947. makeUnitStopWalkingByClearingPathProgressState changes nothing. Outside the group, on top of the twelve members, resetUnitMovementState (with its callees), setDestinationForUnit, setWorkplaceBuildingEntryAsTarget, addResourceToStockpile, buildingIsAccessible, updateBuildingSignpostCounter and getStorageBuildingForResourceTypeAndAmount change nothing; the last four are members of other groups, so with the option on they are off the /GL list already, and naming one would merge two groups. With every .cpp of main as the build list, cmake/function-visibility-units.py makes 25 wrapper units holding 155 source files (150 before): the three units and the two callees join the group that holds hasUnitReachedDestination, and no other file changes group. CMake reads this file only with the option on, so the default build is unchanged. Real builds on main e62246a, BUILD_OK and 0 failures each: - full, option on: every .cpp of main with all function and data resolvers on (the 3 files that don't compile there left out: findBestAttackTileByPathCost, resetTileAndClearMoat, TransformAndRenderPercentage), 3,036 files and 3,054 functions, against main e62246a built the same way. Two full builds of the branch's side: one with the three entries without getDestination2EqualsGivenCoordinates and standUpIfSeated (UpdatePriest's as it is now), which reads UpdatePeasant 96.0% / 87.1%, UpdateMiller 96.5% / 93.0% and UpdatePriest 100.0% / 100.0%; and this change, which reads the three 100.0% / 100.0%. Against main nothing else reads differently in either. - small, both modes: main's /GL list, every .cpp that reads Unit::disappearFadeAlphaCountdown, the twelve units of sourcehold#515, sourcehold#516 and sourcehold#518 (nine in sourcehold#534, three with an entry before it) and these three with their callee closures, standUpAllTribeUnits and updatePeasantSeatingAtBuilding, and every file of a group that touches them, 494 files and 504 functions. All fifteen units read 100.0% / 100.0% in both modes. UpdateFireBallistaBuilding: with the option off, where this file is not read, 100.0% / 100.0% with the 494 files and 99.6% / 95.5% with 492 (without standUpAllTribeUnits and updatePeasantSeatingAtBuilding), so its reading changes with the set of files built; with the option on, 99.6% / 95.5% with the 494 files, and main was not built with those files and the option on, so that case is not settled. It reads 100.0% / 100.0% in both full builds, this change's and main's. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Dec 2, 2026
…(100%) (sourcehold#545) * reimplement: SHC_3BB0A8C1_0x00540440 100.0% Reimplemented Units::UpdateHealer at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: e368a00 at 47.79%, 2d6e422 at 57.41%, 794dcd1 at 57.61%, and the style commit 974c32f), through the forms on our development branches (94.1% there). What the match needed, against that text: - Behind the two searches for a plague cloud that have an else path, the original computes the unit's offset once, in front of the test (0x005405D5 and 0x005408EB: mov ecx, [slot]; imul ecx, ecx, 0x490; cmp eax, ebx), and both arms store through ecx. That is an if / else with the store both arms share written once behind it: animationCycleNumber at the first (0x00540611 and 0x0054064C are the two copies the compiler made of it), destinationNeeded at the second. The text had an early return in the first arm and the shared store in each arm, with a local copy of the slot at the first site; that loads the slot in front of the test and multiplies in each arm, and it changes the order of the stores. quick_diff with the group's callees in the unit: 0.9472 -> 0.9611 with the second site, 0.9782 with both. - The random number for the apothecary's choice is declared where the original masks it, behind the six stores (and edx, 7 at 0x005406EF, kept in esi over the call): at the top of the block it takes ebp. 0.9782 -> 0.9860, and what is left there is the same bytes written two ways (0xd8f0 and -0x2710, 0xff and -1). - The last exit stores the cloud's velocity in front of destinationNeeded, as the original does (0x00540CC6, 0x00540CCF), and the return that closed that arm is gone: with the two sites above written as they are, the arm falls out of the chain like the others (the same object code with and without it). Number casts to UnitState and the two numbers stored into cachedState are the enum's names, calls that return BOOLEnum are tested by truthiness, and the cloud's frame value 0x3f8 is decimal. disappearFadeAlphaCountdown and the frame tables are char and the random number is masked with 7, so the `(char)` and `(byte)` casts on them are gone. None of these changes the object code. `else if (random <= 7)` is always true behind `& 7`: the original tests it (0x00540763), a comment says so, and a plain else reads 0.9609. compiler-flags-gl.txt gets UpdateHealer.cpp only: the callees it has to see are on main's list already (quick_diff 0.6464 alone; without hasUnitReachedDestination 0.6867, checkIfCitizenUnitIsAliveBasedOnState 0.8556, hasTunnelerNotFinishedDigging 0.9633). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0055DA50 100.0% Reimplemented Units::UpdateSpearman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: be18ccc at 38.12%, 0816e82 at 50.99%, 6565c1b, and the style commit 974c32f), through the forms on our development branches (93.6% there). What the match needed, against that text: - The call of UnitsState::returnFalseStub (0x00533090, `xor eax, eax; ret 4`, 100% on main). The original calls it where no ladder was found and keeps the slot in edx over the call (0x0055DE0E: push edx; mov ecx, <units>; call; imul edx, edx, 0x490), so it knew which registers the stub writes, and it did not drop the call. With the stub's body in the unit a call whose result nobody reads is dropped (as a plain function and with __declspec(noinline) alike), and with the body out of sight the slot is loaded again behind it. Tested in an if whose arms both store US_STATE_2Unk, the call stays, the test goes, and the code is the original's. A one-line comment says so. - The wall attack reads the tile's logic entry once into a local and tests the wall bit at each of its four uses (`logic & L_WALL_OR_GATEHOUSE`), in place of a local that held the masked value: the original loads the entry into edx, the building into esi, and only then masks into edi (0x0055E353 to 0x0055E364). 0.9581 -> 0.9668 in quick_diff with the callees named below in the unit. - The dig state ends as main's UpdatePikeman's does: the unit on the tile as `int const occupant`, and the two closing stores written in the arm for a finished tile and behind the block (once: 0.9668 against 0.9804). - The fill state's moat owner goes through a local for returnOwnedMoatAtTile's result, as in main's UpdateSlave (0.9804 -> 0.9826, where what is left is the same bytes written two ways: 0xffff and -1, `call esi` for the import, `test dl, bl`). - The warning's file name is main's s_General_Warning11_wav_005abe28 (the original pushes 0x005ABE28). Number casts to UnitState are the enum's names, the two moat bits and the wall bit are LogicHelpers' names, calls that return BOOLEnum and IsGateOrTowerArray are tested by truthiness, the damage of a hit on a building is an if / else (it was a ternary), every case ends in `return;`, and the casts that did nothing are gone (`(char)` on disappearFadeAlphaCountdown and the frame tables, `(short)` on BuildingLayer and on both operands of the dig tile's x): none of these changes the object code. advanceMoatDigProgress and removeMoat stay compared with 1, as in UpdatePikeman: a truth test reads 0.9811. The owner is read from the unit again where the original reads it again: in the test at 0x0055DF9F, as an argument of processDamageToBuildingThunk (0x0055E3D2), into the wall attack's `attacker` (0x0055E48C), and in the two tests at 0x0055EAC6 and 0x0055EB6C. Through the function's `owner` these read 0.9242, 0.9363, 0.8982, 0.9479 and 0.9240. The player's field at 0x2274 is written aiHoldBackTicks, the name main's PlayerData.hpp has for it since the header sync d134c77 (it was aiControlStatusRelated; same type, same offset): two lines, the same object code. compiler-flags-gl.txt gets UpdateSpearman.cpp only: xyAreValid, returnFalseStub, findAndDestroyAdjacentEnemyLadder, hasUnitReachedDestination and changeDestinationByAmount are on main's list already (quick_diff 0.5408 alone). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * cmake: function-visibility.txt entries for UpdateHealer and UpdateSpearman Two new entries, so that the two units read with OPENSHC_FUNCTION_VISIBILITY_UNITS on what they read in the default build. Both join the group that holds hasUnitReachedDestination. UpdateHealer names three callees, all members of that group already. UpdateSpearman names three members (xyAreValid, hasUnitReachedDestination, changeDestinationByAmount) and two /GL files from outside it, returnFalseStub and findAndDestroyAdjacentEnemyLadder, which join the group with it: no other .cpp calls either, so no other function sees a body it didn't see before or loses one. Each caller-callee pair is measured as sourcehold#491's were (quick_diff, the unit's file with the callee files pasted in front of it, against the unit alone). The callees tried are the group's members that the unit calls directly or through another member it calls; one is named when leaving it out lowers the ratio, and the named set reads what the whole set reads: - UpdateHealer 0.6464 alone, 0.9860 with its three: without hasUnitReachedDestination 0.6867, checkIfCitizenUnitIsAliveBasedOnState 0.8556, hasTunnelerNotFinishedDigging 0.9633. Not named (no change): commitUnitLocation, setupUnitSharingCurrentTilePosition, setupUnitSharingTileIDs, makeUnitStopWalkingByClearingPathProgressState. - UpdateSpearman 0.5408 alone, 0.9826 with its five: without hasUnitReachedDestination 0.5580, xyAreValid 0.9370, changeDestinationByAmount 0.9614 (each measured on the three members alone, which read 0.9637); with findAndDestroyAdjacentEnemyLadder on top of the three 0.9725, with returnFalseStub 0.9737. The original keeps the unit's offset in esi over the first (0x0055DF59, stores through esi at 0x0055DF63) and the slot in edx over the second (0x0055DE14, used at 0x0055DE19). On top of the named callees, each other /GL callee the unit calls was tried one at a time, without its own callees: none changes a ratio. What 0.9860 and 0.9826 leave are lines quick_diff writes two ways (0xffff and -1, an import called through a register); the builds in the pull request read the two units 100.0%. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gynt
added a commit
that referenced
this pull request
Dec 4, 2026
…for unit state 123 and entity type 35) (#544) * UnitState, EntityType: name unit state 123 and entity type 35 UnitState gets US_UNKNOWN_123 = 123 and EntityType gets ET_UNKNOWN_35 = 35, one line each, named as the enums' other values without a known meaning are (US_UNKNOWN_120, US_UNKNOWN_121, ET_UNKNOWN_8, ET_UNKNOWN_30). Both are numbers the original has in UpdateSlinger 0x00572E80, which the next commit adds: - 123 is the highest case of its switch on the state (`cmp eax, 0x7b` at 0x00572EF4), the state it stores behind moveToFreeTileNearby when that call left the unit in US_MOVE_TO_DESTINATION (`add ecx, 0x7b` at 0x005732D3: 123 there, 4 for US_RELOAD_WEAPONUnk otherwise), and the value Unit::field_0x2c4 is tested for in front of that call (0x0057329D). field_0x2c4 is the short behind state and cachedState, and the block it guards stores state 123, so the field holds a state number and the test reads with the same name. - 35 is the entity type of the stone the slinger throws (`push 0x23` at 0x00573C8B, shootProjectile's second argument). ET_SLINGER is 33; 35 has no name yet. Four files on main write `(UnitState)123` for the same case label and the same store (UpdateArabianArcher, UpdateCrossbowman, UpdateCrusaderArcher, UpdateFireThrower). This commit leaves them as they are. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00572E80 100.0% Reimplemented Units::UpdateSlinger at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: 30448d6 at 28.29%, a43cf47 and e61e5a5 at 31.60%, 6565c1b, and the style commit 974c32f), through the forms on our development branches (96.5% there with OPENSHC_FUNCTION_VISIBILITY_UNITS on). What the match needed, against that text: - Where the sling is loaded and the target is a building, half the building's size is written in both sums (`.x + widthOrHeight / 2`, `.y + widthOrHeight / 2`) in place of a local for it. The original divides once (0x0057376D: cdq; sub eax, edx; sar edx, 1) and moves the quotient out of eax (0x00573770), so the target's y is in eax on this arm as on the arm for a unit (0x00573732), and edx is free for the zero that the test behind the join compares with and the state store uses (xor edx, edx at 0x0057377F, cmp ecx, edx at 0x00573781, the store at 0x005737B6, an exit that five jumps of another state share). With the local the quotient stays in eax, the y takes edx, the test is a `test ecx, ecx` and the store an immediate with an exit of its own. quick_diff with hasUnitReachedDestination in the unit: 0.9814 -> 0.9955 (1346 -> 1340 instructions, the original's count), and what is left is the same bytes written two ways (0xffff and -1, 0xfffe and -2). Number casts to UnitState are the enum's names. State 123 is US_UNKNOWN_123 in the case label, in the store behind moveToFreeTileNearby and in the test of field_0x2c4, the short behind state and cachedState, which holds a state too (0x00572EF4, 0x005732D3, 0x0057329D); the projectile is ET_UNKNOWN_35 (push 0x23 at 0x00573C8B). Both names come with the header commit before this one. The wall and keep bits are LogicHelpers' names, calls that return BOOLEnum, IsGateOrTowerArray and animationCycleNumberHasJustIncremented are tested by truthiness, the damage of a hit on a building and the state behind moveToFreeTileNearby are if / else (they were ternaries), the fade step is decremented without a pointer cast, and the casts that did nothing are gone (`(char)` on disappearFadeAlphaCountdown and the frame tables, `(short)` on BuildingLayer, `(int)` on widthOrHeight and on the fixedRng sum): none of these changes the object code. The `(short)` where mapTimeInTicks (uint) is stored into isSelectable_OR_matchTime (short) stays, as main's other units write that store. Kept, each with a comment and with what the other form reads: - `int building;` in the wall attack without a value: it is read behind the if / else, and with `= 0` (0.9799) or with the tile's building read in front of the test (0.9735) the match is lost. - `target > -1` where the stone is thrown: the original compares with the register that holds -1 (0x00573B4A); `>= 0` reads 0.9940. - The two arms on movementType_OR_targetUnitID that store the same pair: the original has the compare and one copy of the stores (0x005731BC); one arm reads 0.9951. The owner is read from the unit again where the original reads it again: as an argument of processDamageToBuildingThunk (0x005734FD) and into the wall attack's `attacker` (0x005735B2). Through the function's `owner` these read 0.9810 and 0.9269. compiler-flags-gl.txt gets UpdateSlinger.cpp only: hasUnitReachedDestination is on main's list already (quick_diff 0.4706 alone). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * cmake: function-visibility.txt entry for UpdateSlinger One new entry, so that UpdateSlinger reads with OPENSHC_FUNCTION_VISIBILITY_UNITS on what it reads in the default build. It joins the group that holds hasUnitReachedDestination and names that callee, the one member it calls. Measured as #491's pairs were (quick_diff, the unit's file with the callee's file pasted in front of it, against the unit alone): 0.4706 alone, 0.9955 with hasUnitReachedDestination. Each other /GL callee the unit calls was tried one at a time on top of it, without its own callees: none changes the ratio. What 0.9955 leaves are lines quick_diff writes two ways (0xffff and -1, 0xfffe and -2); the builds in the pull request read the unit 100.0%. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: Gynt <gynt@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#416, #433 and #438 put six callers on
cmake/compiler-flags-gl.txtafter #398 without an entry incmake/function-visibility.txt. Each gets one here, at its address, with its callees in address order. The /GL list is unchanged.MenuItemRenderFunction_InGameMenu_MainButtons(#416)ButtonGmData::getPictureNumberInGmMenuItemActionHandler_Roundtable_Main(#416)GameSynchronyState::isAIPlayerUpdateFireWatch(#433)checkIfCitizenUnitIsAliveBasedOnState,hasUnitReachedDestinationUpdateGhost(#416)hasUnitReachedDestinationUpdateHunterDog(#433)makeUnitStopWalkingByClearingPathProgressState,checkIfCitizenUnitIsAliveBasedOnState,hasUnitReachedDestination,hasTunnelerNotFinishedDiggingUpdateCageDog(#438)makeUnitStopWalkingByClearingPathProgressState,checkIfCitizenUnitIsAliveBasedOnState,hasUnitReachedDestination,tryAttackUnitIDHow each edge was measured (as for #398): quick_diff of the caller with the callee files compiled into its unit ahead of it, against the caller alone, on main 7c2e4d6, with every function resolver that has a .cpp and every struct resolver on. The callees tried are the caller's /GL-listed callees at a lower address than the caller. A callee is listed when it raises the caller's ratio on its own, or when leaving it out of the full set lowers it. Each listed set reads what all of the caller's /GL callees read together. The commit message gives the leave-one-out numbers and the callees that change nothing.
#473 and #475 put
UpdateSiegeTentandUpdateHorseArcher_DoShootingon the list. Neither calls a /GL-listed function, so neither gets an entry.UpdateHorseArchercallsUpdateHorseArcher_DoShooting, but reads worse with its body (0.9929 with its present entry, 0.9906 withUpdateHorseArcher_DoShootingadded), so its entry stays as it is.cmake/function-visibility-units.py, with every .cpp of main as the build list, now makes 24 units holding 116 source files (108 before). There are no internal-name clashes, and the 13 skipped names are the same as before.🤖 Generated with Claude Code